//*********************************************************************
//		Copyright (c) 2003 - 2008 Microsoft Corporation.
//      This code is provided under Microsoft Public License, which can be found at
//      http://www.microsoft.com/resources/sharedsource/licensingbasics/publiclicense.mspx 
//
// @File: RepConnect.cs
//
// Purpose: Connect to Repostiory Dialog
//
//
//
// Notes: 
//
//
//	
// History: 
//     @Version: V2.1
//
//     08/18/08 PGV 2.1.001.0 Starting V2.1 (based on 2.0.030.0 code)
//
// @EndHeader@
//*********************************************************************

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;

namespace H2V2.ConfigUtility
{
	/// <summary>
	/// Summary description for RepView.
	/// </summary>
	public class RepConnect : System.Windows.Forms.Form
	{
		private System.Windows.Forms.Button btCancel;
		private System.Windows.Forms.Label lbPwd;
		private System.Windows.Forms.Label lbUser;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.TextBox tbPwd;
		private System.Windows.Forms.TextBox tbUser;
		private System.Windows.Forms.TextBox tbDb;
		private System.Windows.Forms.TextBox tbServer;
		private System.Windows.Forms.CheckBox cbIntSec;
		private System.Windows.Forms.Button btConnect;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

        public RepConnect ()
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent ();

            tbServer.Text = MainForm.stRep.Server;
            tbDb.Text = MainForm.stRep.Database;
            cbIntSec.Checked = MainForm.stRep.bIntSec;

            if (!cbIntSec.Checked)
            {
                tbUser.Text = MainForm.stRep.User;
                tbUser.Enabled = true;
                tbPwd.Enabled = true;
            }
        }

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.btCancel = new System.Windows.Forms.Button();
			this.btConnect = new System.Windows.Forms.Button();
			this.lbPwd = new System.Windows.Forms.Label();
			this.lbUser = new System.Windows.Forms.Label();
			this.label2 = new System.Windows.Forms.Label();
			this.label1 = new System.Windows.Forms.Label();
			this.tbPwd = new System.Windows.Forms.TextBox();
			this.tbUser = new System.Windows.Forms.TextBox();
			this.tbDb = new System.Windows.Forms.TextBox();
			this.tbServer = new System.Windows.Forms.TextBox();
			this.cbIntSec = new System.Windows.Forms.CheckBox();
			this.SuspendLayout();
			// 
			// btCancel
			// 
			this.btCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
			this.btCancel.Location = new System.Drawing.Point(232, 248);
			this.btCancel.Name = "btCancel";
			this.btCancel.Size = new System.Drawing.Size(104, 23);
			this.btCancel.TabIndex = 31;
			this.btCancel.Text = "Cancel";
			// 
			// btConnect
			// 
			this.btConnect.DialogResult = System.Windows.Forms.DialogResult.OK;
			this.btConnect.Location = new System.Drawing.Point(80, 248);
			this.btConnect.Name = "btConnect";
			this.btConnect.Size = new System.Drawing.Size(112, 23);
			this.btConnect.TabIndex = 30;
			this.btConnect.Text = "Connect";
			this.btConnect.Click += new System.EventHandler(this.btConnect_Click);
			// 
			// lbPwd
			// 
			this.lbPwd.Enabled = false;
			this.lbPwd.Location = new System.Drawing.Point(16, 184);
			this.lbPwd.Name = "lbPwd";
			this.lbPwd.TabIndex = 29;
			this.lbPwd.Text = "Password:";
			this.lbPwd.TextAlign = System.Drawing.ContentAlignment.TopRight;
			// 
			// lbUser
			// 
			this.lbUser.Enabled = false;
			this.lbUser.Location = new System.Drawing.Point(16, 136);
			this.lbUser.Name = "lbUser";
			this.lbUser.TabIndex = 28;
			this.lbUser.Text = "User:";
			this.lbUser.TextAlign = System.Drawing.ContentAlignment.TopRight;
			// 
			// label2
			// 
			this.label2.Location = new System.Drawing.Point(16, 56);
			this.label2.Name = "label2";
			this.label2.TabIndex = 27;
			this.label2.Text = "Database:";
			this.label2.TextAlign = System.Drawing.ContentAlignment.TopRight;
			// 
			// label1
			// 
			this.label1.Location = new System.Drawing.Point(32, 16);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(88, 23);
			this.label1.TabIndex = 26;
			this.label1.Text = "Server:";
			this.label1.TextAlign = System.Drawing.ContentAlignment.TopRight;
			// 
			// tbPwd
			// 
			this.tbPwd.Enabled = false;
			this.tbPwd.Location = new System.Drawing.Point(128, 184);
			this.tbPwd.MaxLength = 128;
			this.tbPwd.Name = "tbPwd";
			this.tbPwd.PasswordChar = '*';
			this.tbPwd.Size = new System.Drawing.Size(184, 20);
			this.tbPwd.TabIndex = 25;
			this.tbPwd.Text = "";
			// 
			// tbUser
			// 
			this.tbUser.Enabled = false;
			this.tbUser.Location = new System.Drawing.Point(128, 136);
			this.tbUser.MaxLength = 256;
			this.tbUser.Name = "tbUser";
			this.tbUser.Size = new System.Drawing.Size(184, 20);
			this.tbUser.TabIndex = 24;
			this.tbUser.Text = "";
			// 
			// tbDb
			// 
			this.tbDb.Location = new System.Drawing.Point(128, 56);
			this.tbDb.MaxLength = 256;
			this.tbDb.Name = "tbDb";
			this.tbDb.Size = new System.Drawing.Size(184, 20);
			this.tbDb.TabIndex = 22;
			this.tbDb.Text = "";
			// 
			// tbServer
			// 
			this.tbServer.Location = new System.Drawing.Point(128, 16);
			this.tbServer.MaxLength = 256;
			this.tbServer.Name = "tbServer";
			this.tbServer.Size = new System.Drawing.Size(184, 20);
			this.tbServer.TabIndex = 21;
			this.tbServer.Text = "";
			// 
			// cbIntSec
			// 
			this.cbIntSec.Checked = true;
			this.cbIntSec.CheckState = System.Windows.Forms.CheckState.Checked;
			this.cbIntSec.Location = new System.Drawing.Point(128, 96);
			this.cbIntSec.Name = "cbIntSec";
			this.cbIntSec.Size = new System.Drawing.Size(136, 24);
			this.cbIntSec.TabIndex = 23;
			this.cbIntSec.Text = "Integrated Security";
			// 
			// RepConnect
			// 
			this.AcceptButton = this.btConnect;
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.CancelButton = this.btCancel;
			this.ClientSize = new System.Drawing.Size(408, 302);
			this.Controls.Add(this.btCancel);
			this.Controls.Add(this.btConnect);
			this.Controls.Add(this.lbPwd);
			this.Controls.Add(this.lbUser);
			this.Controls.Add(this.label2);
			this.Controls.Add(this.label1);
			this.Controls.Add(this.tbPwd);
			this.Controls.Add(this.tbUser);
			this.Controls.Add(this.tbDb);
			this.Controls.Add(this.tbServer);
			this.Controls.Add(this.cbIntSec);
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
			this.Name = "RepConnect";
			this.Text = "Connect to Repository";
			this.ResumeLayout(false);

		}
		#endregion

		private void btConnect_Click(object sender, System.EventArgs e)
		{
			DbInstaller dbi;
			try
			{
				if (cbIntSec.Checked)
				{
					dbi = new DbInstaller (tbServer.Text, tbDb.Text);
				}
				else
				{
					dbi = new DbInstaller (tbServer.Text, tbDb.Text, tbUser.Text, tbPwd.Text);
				}

				RepView frv = new RepView (ref dbi);

				Close ();

				frv.ShowDialog ();
			}
			catch (Exception ex)
			{
				MessageBox.Show (ex.Message, "Exception", MessageBoxButtons.OK, MessageBoxIcon.Error);
			}

		}
	}
}
